//
//  JuBaoChaXunTableViewController.swift
//  xdjcy
//
//  Created by Henry on 15/12/8.
//  Copyright (c) 2015年 Henry. All rights reserved.
//

import UIKit

class JuBaoChaXunTableViewController: UITableViewController, UIGestureRecognizerDelegate{
    @IBOutlet weak var txt_code: XHTextField!
    
    @IBOutlet weak var lbl_content_text: UILabel!
    @IBOutlet weak var lbl_content: UILabel!
    @IBOutlet weak var lbl_status_text: UILabel!
    @IBOutlet weak var lbl_status: UILabel!
    @IBOutlet weak var txt_picker: GSIconPickerTextField!
    @IBOutlet weak var btn_apply: ACPButton!
    var codeNameList:Array<TypeModel> = Array<TypeModel>()
    var progress:MBProgressHUD!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.navigationController?.interactivePopGestureRecognizer.delegate = self
        
        self.navigationController?.navigationBar.tintColor =  UIColor.whiteColor()
        var backButton = UIBarButtonItem(image: UIImage(named: "back"), style: UIBarButtonItemStyle.Bordered, target: self, action: "goBack")
        self.navigationItem.leftBarButtonItem = backButton
        
        btn_apply.setFlatStyle(MainColor, andHighlightedColor: MainColor)
        btn_apply.setBorderStyle(MainColor, andInnerColor: MainColor)
        btn_apply.setTitleColor(UIColor.whiteColor(), forState: UIControlState.allZeros)
        
        txt_picker.layer.borderWidth = 0.8
        txt_picker.layer.borderColor = UIColor(white: 0.1, alpha: 0.2).CGColor
        
        txt_code.required = true
        txt_code.maxTextLength = 25
        
        
        progress = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
        MenuTypeRN.sharedInstance.getBasicList { (result, message, cardList, jobLevelList, identityList, crimesList) -> Void in
            
            if result
            {
                if cardList.count > 0
                {
                    self.codeNameList = cardList
                    self.txt_picker.list = self.codeNameList
                }
            }
            self.progress.hide(true)
        }
        
        lbl_status.hidden = true
        lbl_status_text.hidden = true
        lbl_content.hidden = true
        lbl_content_text.hidden = true
                
    }
    
    func goBack()
    {
        self.navigationController?.popViewControllerAnimated(true)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    @IBAction func btn_queding(sender: AnyObject) {
        
        
        if txt_picker.text != "" && txt_code.validate()
        {
            progress = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
            MenuTypeRN.sharedInstance.ReportSearchResult(codeNameList[txt_picker.selectedIndex].typeCode!, report_idcard: txt_code.text) { (result, message, jsonResult) -> Void in
                var model = ReportModel()
                model = jsonResult
                println(model.Id)
                if model.Resolve_status != nil
                {
                    self.progress.hide(true)
                    self.lbl_status.hidden = false
                    self.lbl_status_text.hidden = false
                    self.lbl_content.hidden = false
                    self.lbl_content_text.hidden = false
                    self.lbl_status_text.text = model.Resolve_status
                    self.lbl_content_text.text = model.Resolve_content
                }
                else
                {
                    self.progress.mode = MBProgressHUDMode.Text
                    self.progress.labelText = "没有查询结果"
                    self.progress.hide(true, afterDelay: 2)
                }
            }

        }
        else
        {
            progress = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
            progress.mode = MBProgressHUDMode.Text
            progress.labelText = "请填写完整信息"
            progress.hide(true, afterDelay: 2)
        }
    }
    
    // MARK: - Table view data source
    //
    //    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    //        // #warning Potentially incomplete method implementation.
    //        // Return the number of sections.
    //        return 0
    //    }
    //
    //    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    //        // #warning Incomplete method implementation.
    //        // Return the number of rows in the section.
    //        return 0
    //    }
    //
    /*
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as! UITableViewCell
    
    // Configure the cell...
    
    return cell
    }
    */
    
    /*
    // Override to support conditional editing of the table view.
    override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    // Return NO if you do not want the specified item to be editable.
    return true
    }
    */
    
    /*
    // Override to support editing the table view.
    override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == .Delete {
    // Delete the row from the data source
    tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
    } else if editingStyle == .Insert {
    // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }
    }
    */
    
    /*
    // Override to support rearranging the table view.
    override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
    
    }
    */
    
    /*
    // Override to support conditional rearranging of the table view.
    override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    // Return NO if you do not want the item to be re-orderable.
    return true
    }
    */
    
    /*
    // MARK: - Navigation
    
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    }
    */
    
}
